<?php

class tabelClass
{
	var $connection;
	var $dataset;
	var $datasetsub;
	var $sql;
	var $field;
	
	var $width;
	var $widthno;
	var $border;
	var $cellpadding;
	var $cellspacing;
	var $frameborder;
	var $widthKolom;
	var $alignKolom;
	var $dataPerPage;
	var $index;
	var $aksiAjax;
	var $aksiEdit;
	var $divEdit;
	var $dataEdit;
	var $divAjax;
	var $divout;
	var $output;
	var $indexoutput;
	var $indexlink;
	var $indexurai;
	var $tipeData;
	var $dataAjax;
	var $indexhide;
	var $indexEdit;
	var $drillDown;
	var $childPage;
	var $showRdPanel;
	var $showIcon;
	var $arrayIcon;
	var $kotakIndex;
	var $judulTabel;
	var $jsPilih;
	var $tipeLink;
	var $jspopwindow;
	var $titleLink;
	var $showChkPanel;
	var $formCheck;
	var $FormName;
	// variabel sorting
	var $indexSort;
	var $jsSort;
	var $caraOrder;
	var $dataSort;
	
	// variabel pembanding
	var $indexBanding;
	var $nilaiBandingRubah;
	var $nilaiBandingLawan;
	var $styleRubah;
	var $jsEdit;
	var $jsHapus;
	
	
	var $EditJs;
	var $HapusJs;
	var $editDatarow;
	var $justedit;
	var $justeditbtn;
	
	var $banyakData;
	var $editData;
	var $tipe;
	
	var $indexRow;
	var $tblProses;
	var $headerProses;
	var $jsProses;
	
	var $jsFillOutput;
	var $bandingRadio;
	var $nilaiBandingRadio;
	

	var $centang;
	var $centangabsen;
	var $headerCentang;
	var $headerCentangabsen;
	
	var $action;
	var $editButtonJs;
	var $hapusButtonJs;
	var $id;
	var $Clickview;
	var $TitleToView;
	var $UrlToView;	
	var $TypeClickview;
	var $FileClickview;
	var $DataClickview;
	var $WidthClickview;
	var $HeightClickview;
	var $EventClickview;
	var $DivClickview;
	
	function tabelClass()
	{
		$this->width = "100%";
		$this->border = "0";
		$this->cellpadding = "0";
		$this->cellspacing = "0";
		$this->frameborder = "0";
		$this->field = array();
		$this->widthKolom = array();
		$this->alignKolom = array();
		$this->dataPerPage = "10";
		$this->index = "1";
		$this->widthno = "1%";
		$this->editData = false;
		$this->tipe = "";
		$this->drillDown = false;
		$this->showRdPanel = false;
		$this->showChkPanel = false;
		$this->showIcon = false;
		$this->kotakIndex = "cariIndexPilih";
		$this->jsEdit = "editData";
		$this->jsHapus = "hapusData";
		$this->formCheck = "selectAll";
		$this->tblProses = false;
		$this->headerProses = "Proses";
		$this->FormName ="";
		$this->DivName ="";
		
		$this->editData = false;
		$this->EditJs = "";
		$this->Hapusjs = "";
		$this->justedit = false;
		$this->justeditbtn = "";
		$this->bykdata;
		
		
		$this->centang = false;
		$this->headerCentang = "Pakai";
		$this->centangabsen = false;
		$this->headerCentangabsen = "Siap Ditunjuk";
		$this->action = false;
		$this->id = "";
		
		$this->Clickview = false;
		$this->TypeClickview="window";
		$this->TitleToView = "click to view detail.";		
		$this->EventClickview = "onClick";
		$this->DivClickview = "DivDrillTable";
	}
	function jumdata(){
		$this->execSubsql();
		$this->execQuery();	
		$totalData = $this->dataset->size();
		return $totalData;
	}
	
	function drawTabel()
	{
		$this->execSubsql();
		$this->execQuery();
		$indexhide_array2 = explode(";", $this->indexhide);
		$banyakIndexHide = count($indexhide_array2);
		$banyakKolom = $this->getColumnCount() - $banyakIndexHide;
		$balik = "";
		$totalData = $this->dataset->size();
		if ($totalData > 0)
		{
			/*$balik .= "<form name=\"".$this->FormName."\" id=\"".$this->FormName."\">";
			$balik .= "<div name=\"".$this->divAjax."\" id=\"".$this->divAjax."\" style=\"margin-top:20px\">";*/
			$balik .= "<table width=\"$this->width\" border=\"0\" cellpadding=\"$this->cellpadding\" cellspacing=\"$this->cellspacing\" frameborder=\"$this->frameborder\">";
			$balik .= "<tr>";
			if ($this->showIcon == true) {
				$balik .= "<td>".$this->drawIcon()."</td>";
			}
			$balik .= "<td align=\"right\" class=\"drawindex\">".$this->drawIndex()."</td>";
			$balik .= "</tr>";
			$balik .= "</table>";
			$balik .= "<div id=\"masterdiv\">";
			$balik .= "<table width=\"$this->width\" border=\"$this->border\" cellpadding=\"$this->cellpadding\" cellspacing=\"$this->cellspacing\" frameborder=\"$this->frameborder\" class=\"tabelsClass\">";
			$balik .= "<colgroup>";
			$balik .= "<col id=\"col1_1\"></col>";
			$balik .= "<col id=\"col1_2\"></col>";
			$balik .= "<col id=\"col1_3\"></col>";
			$balik .= "</colgroup>";			
			//$balik .= "<input type=\"hidden\" name=\"adadata\" id=\"adadata\" value=\"ada\">";
			$balik .= $this->drawHeader();
			$balik .= $this->drawData();
			$balik .= $this->drawfooter();
			$balik .= "</table>";
			$balik .= "</div>";
			/*$balik .= "</div>";
			$balik .= "</form>";*/
			$balik .= "<div id=\"DivDrillTable\" class=\"Divdrill\"></div>";
		}else{
			/*$balik .= "<form name=\"".$this->FormName."\" id=\"".$this->FormName."\">";
			$balik .= "<div name=\"".$this->divAjax."\" id=\"".$this->divAjax."\" style=\"margin-top:20px\">";*/
			$balik .= "<input type=\"hidden\" name=\"adadata\" id=\"adadata\" value=\"kosong\">";
			$balik .= "<table border=0>";
			$balik .= "<tr>";
			if ($this->showIcon == true) {
				$balik .= "<td>".$this->drawIcon()."</td>";
			}
			$balik .= "</tr>";
			$balik .= "</table>";
			$balik .= "<table border=0 width=100% cellpadding=\"0\" cellspacing=\"0\">";
			$balik .= "<tr><td style=\"border-top: 1px solid #cceac4;\" >&nbsp;</td></tr>";
			$balik .= "<tr ><td align=\"center\"><b>DATA KOSONG</b></td></tr>";
			$balik .= "<tr><td style=\"border-bottom: 1px solid #cceac4;\">&nbsp;</td></tr>";
			$balik .= "<input type=\"radio\" name=\"radioPanel\" value=\"null\" style=\"display:none\">";
			$balik .= "</table>";
			/*$balik .= "</div>";
			$balik .= "</form>";*/

		}
		return $balik;
	
	}


	function drawfooter()
	{
		$jumkolom = $this->getColumnCount()+1;
		$header .= "<tr>";
		if (($this->editDatarow) or ($this->justedit))
		{
			$jumkolom = $jumkolom+1;
			$header .= "<th class=\"colorTh\" colspan='".$jumkolom."'>&nbsp;</th>";
		}else{
			$header .= "<th class=\"colorTh\" colspan='".$jumkolom."'>&nbsp;</th>";
		}
		$header .= "</tr>";
		return $header;
	}


	function drawHeader()
	{
		$indexhide_array2 = explode(";", $this->indexhide);
		$banyakIndexHide = count($indexhide_array2);
		$banyakKolom = $this->getColumnCount() - $banyakIndexHide;
		$header .= "<tr>";
		$header .= "<th width='".$this->widthno."' class=\"colorTh\">No.</th>";		
		if ($this->showRdPanel == true)
		{
			$header .= "<th width='".$this->widthno."' class=\"colorTh\">&nbsp;</th>";
		}
		else if ($this->showChkPanel == true)
		{
			$header .= "<th width='".$this->widthno."' class=\"colorTh\"><input type=\"checkbox\" id=\"\" value=\"".$indexEditDrill."\" onclick=\"".$this->formCheck."(this,".$this->FormName.");\" title=\"Pilih Semua\" style=\"border: 1px solid #ffffff;\"></th>";
			
		}
		else {
			$header .= "<th width='".$this->widthno."' class=\"colorTh\">No.</th>";
		}
		$indexhide_array = explode(";", $this->indexhide);
		for ($i=0; $i<$banyakKolom; $i++)
		{
			if (!in_array(strval($i), $indexhide_array))
			{
				$header .= "<th width='".$this->widthKolom[$i]."' class=\"colorTh\">";
				if ($this->indexSort == "")
				{
					if ($this->field[$i] == "") {
						$header .= $this->dataset->get($i);
					} else { 
						$header .= $this->field[$i];
					}
				}
				else
				{
					$indexSortArray = explode(";", $this->indexSort);
					if (in_array(strval($i), $indexSortArray))
					{
						if ($this->field[$i] == "") {
							$header .= "<a href=\"javascript:void(0)\" onclick=\"".$this->jsSort."('".$this->dataset->get($i)."', '".$this->caraOrder."', '".$this->dataSort."')\" title=\"Klik untuk mengurutkan berdasarkan ".$this->dataset->get($i)."\" style=\"display: block; color: #ffffff;\">".$this->dataset->fieldName($i)."</a>";
						} else { 
							$header .= "<span><a href=\"javascript:void(0)\" onclick=\"".$this->jsSort."('".$this->dataset->fieldName($i)."', '".$this->caraOrder."', '".$this->dataSort."')\" title=\"Klik untuk mengurutkan berdasarkan ".$this->field[$i]."\" style=\"display: block; color: #ffffff;\">".$this->field[$i]."</a></span>";
						}
					}
					else
					{
						if ($this->field[$i] == "") {
							$header .= $this->dataset->fieldName($i);
						} else { 
							$header .= $this->field[$i];
						}
					}
				}
				$header .= "</th>";
				}
			else
			{
				continue;
			}
		}
		if ($this->editData)
		{
			$header .= "<th class=\"colorTh\">";
			$header .= "Edit";
			$header .= "</th>";
		}
		else if ($this->tblProses)
		{
			$header .= "<th class=\"colorTh\" width=\"1%\">";
			$header .= $this->headerProses;
			$header .= "</th>";
		}
		
		else if ($this->centang)
		{
			$header .= "<th class=\"colorTh\" width=\"1%\">";
			$header .= $this->headerCentang;
			$header .= "</th>";
		}
		
		else if ($this->centangabsen)
		{
			$header .= "<th class=\"colorTh\" width=\"7%\">";
			$header .= $this->headerCentangabsen;
			$header .= "</th>";
		}
		else if ($this->action)
		{
			$header .= "<th class=\"colorTh\" width=\"20%\">";
			$header .= "Download";
			$header .= "</th>";
		}
		
		else if (($this->editDatarow) or ($this->justedit))
		{
			$header .= "<th class=\"colorTh\">";
			$header .= "Action";
			$header .= "</th>";
		}
		$header .= "</tr>";
		return $header;
	}
	
	function cekString($mystring, $stringCari, $stringGanti)
	{
		$pos = strpos($mystring, $stringCari);
		if ($pos === false)
		{
			return $mystring;
		}
		else
		{
			return str_replace($stringCari, $stringGanti, $mystring);
		}
	}
	
	function drawData()
	{
	
		$indexhide_array2 = explode(";", $this->indexhide);
		$banyakIndexHide = count($indexhide_array2);
		$banyakKolom = $this->getColumnCount() - $banyakIndexHide;
		$nomor = (($this->index-1)*($this->dataPerPage-1)+$this->index);
		$data = "";
		$totalData = $this->dataset->size();
		$indexlink = 0+$this->indexlink;
		$indexurai = 0+$this->indexurai;
		$indexoutput_array = explode(";",$this->indexoutput);	

		
		if ($totalData > 0)
		{
			$row = 0;
			while($this->dataset->next())
			{
				$data .= "<tr onmouseover=\"this.style.backgroundColor='#E8F3F9';\" onmouseout=\"this.style.backgroundColor='#ffffff';\" class=\"BackColor\">";
				$data .= "<td align=\"center\" class='drill' valign=\"middle\">".$nomor."</td>";
				if ($this->showRdPanel == true)
				{
					$arrayIndexEditTemp = explode(";",$this->indexEdit);
					$banyakIndexEditTemp = count($arrayIndexEditTemp);
					$indexEditDrill = "";
					for ($t=0; $t<$banyakIndexEditTemp; $t++)
					{
						$indexEditDrill .= $this->dataset->get($arrayIndexEditTemp[$t]);
						if (($banyakIndexEditTemp-1) != $t)
						{
							$indexEditDrill .= ";";
						}
					}
					$pecahBandingRadio = explode(";", $this->bandingRadio);
					$data .= "<td align='center' class=\"drill\" valign=\"middle\">";
					$data .= "<input type=\"radio\" name=\"radioPanel\" value=\"".$indexEditDrill."\" ";
					if (!empty($this->nilaiBandingRadio))
					{
						if ($this->dataset->get($this->dataset->fieldName($pecahBandingRadio[0])) == $this->nilaiBandingRadio)
						{
							$data .= "checked ";
						}
					}
					$data .= ">";
					$data .= "</td>";
					
				} 
				else if ($this->showChkPanel == true)
				{ 
					$arrayIndexEditTemp = explode(";",$this->indexEdit);
					$banyakIndexEditTemp = count($arrayIndexEditTemp);
					$indexEditDrill = "";
					for ($t=0; $t<$banyakIndexEditTemp; $t++)
					{
						$indexEditDrill .= $this->dataset->get($arrayIndexEditTemp[$t]);
						if (($banyakIndexEditTemp-1) != $t)
						{
							$indexEditDrill .= ";";
						}
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";
					$data .= "<input type=\"checkbox\" name=\"radioPanel[]\" id=\"radioPanel\" value=\"".$indexEditDrill."\">";
					$data .= "</td>";
				}
				else {
					$data .= "<td align=\"center\" class='drill' valign=\"middle\">".$nomor."</td>";
				}
				$indexhide_array = explode(";", $this->indexhide);
				for ($i=0; $i<($banyakKolom); $i++)
				{
					if (!in_array(strval($i), $indexhide_array))
					{
						if($this->Clickview){
							$arrayIndexEditT = explode(";",$this->indexEdit);
							$banyakIndexEditT = count($arrayIndexEditT);
							$indexEditClick = "";
							for ($t=0; $t<$banyakIndexEditT; $t++)
							{
								$indexEditClick .= $this->dataset->get($arrayIndexEditT[$t]);
								if (($banyakIndexEditTemp-1) != $t)
								{
									$indexEditClick .= ";";
								}
							}
						
							if(strtoupper($this->TypeClickview)=="WINDOW"){
								$ClickviewStyle = " style=\"cursor:pointer;\" ".$this->EventClickview."=\"window.location='".$this->UrlToView."&dataView=".$indexEditClick."'\" 
													 title=\"".$this->TitleToView."\" ";
							}
							elseif(strtoupper($this->TypeClickview)=="JSDRILL"){
								$ClickviewStyle = " style=\"cursor:pointer;\" ".$this->EventClickview."=\"getData('".$this->FileClickview."', '".$this->DivClickview."', 'dataView=".$indexEditClick."', '')\" 
													 title=\"".$this->TitleToView."\" ";
							}
							elseif(strtoupper($this->TypeClickview)=="POPUP"){
								$ClickviewStyle = " style=\"cursor:pointer;\" 
													".$this->EventClickview."=\"ShowPopUp('".$this->FileClickview."',
																'dataView=".$indexEditClick."&".$this->DataClickview."',
																".$this->WidthClickview.",".$this->HeightClickview.")\" 
													 title=\"".$this->TitleToView."\" ";
							}
						}
						
						$data .= "<td align='".$this->alignKolom[$i]."' class=\"drill\" valign=\"middle\" ".$ClickviewStyle." >";
						if (($this->indexlink != "") or ($this->drillDown == true))
						{
							if ($i == $indexlink)
							{
								switch ($this->tipeLink)
								{
									case "drill":
										$indexEditDrill = "";
										$arrayIndexEditTemp = explode(";",$this->indexEdit);
										$banyakIndexEditTemp = count($arrayIndexEditTemp);
										for ($t=0; $t<$banyakIndexEditTemp; $t++)
										{
											$indexEditDrill .= $this->dataset->get($arrayIndexEditTemp[$t]);
											if (($banyakIndexEditTemp-1) != $t)
											{
												$indexEditDrill .= ";";
											}
										}
										if (($this->dataset->get($this->dataset->fieldName($this->indexBanding))) == $this->nilaiBandingRubah)
										{
											$gantiStyle = $this->styleRubah;
										}
										
										$data .= "<a href=\"javascript:void(0)\" style=\"color:#AA0000;text-decoration:none;\" onclick=\"";
										$data .= "if (document.getElementById('sub".$nomor.$this->id."').innerHTML == '') {";
										$data .= "getData2('".$this->childPage."', 'sub".$nomor.$this->id."', 'data=".$indexEditDrill."&row=".$row."', 'drill'); } else { ";
										$data .= "document.getElementById('sub".$nomor.$this->id."').style.display = ''; document.getElementById('sub".$nomor.$this->id."').innerHTML = ''}";
										$data .= "\" ".$gantiStyle." title=\"".$this->titleLink."\">";
										$data .= $this->dataset->get($i);
										$data .= "</a>";
										break;
									case "popwindow":
										$dataPop = "";
										$arrayEditPop = explode(";", $this->indexEdit);
										$banyakEditPop = count($arrayEditPop);
										for ($p=0; $p<$banyakEditPop; $p++)
										{
											$dataPop .= $this->dataset->get($arrayEditPop[$p]);
											if ($p != ($banyakEditPop-1))
											{
												$dataPop .= ";";
											}
										}
										if (($this->dataset->get($this->indexBanding)) == $this->nilaiBandingRubah)
										{
											$gantiStyle = $this->styleRubah;
										}
										else
										{
											$gantiStyle = "style=\"color: #00019b\"";
										}
										$data .= "<div id=\"test\" ".$gantiStyle."><a href=\"javascript:void(0)\" onclick=\"".$this->jspopwindow."(".($this->indexRow+1).$row.", this)\" title=\"".$this->titleLink."\">";
										$data .= $this->dataset->get($i);
										$data .= "</a></div>";
										//$data .= "<input type=\"hidden\" name=\"dataHidden".($this->indexRow+1).$row."\" value=\"".$dataPop."\">";
										$data .= "<input type=\"hidden\" name=\"dataHidden".($this->indexRow+1).$row."\" value=\"".$dataPop."\" id=\"dataHidden".($this->indexRow+1).$row."\">";
										break;
									case "filloutput":
										$dataoutput = $this->dataset->get($this->dataset->fieldName($indexoutput));
										$uraioutput = $this->dataset->get($this->dataset->fieldName($indexurai));
										$cariText = "'";
										$cariText2 = "\"";
										$gantiText = "\'";
										$gantiText2 = "\\\"";
										
										$dataoutput2 = $this->cekString($dataoutput, $cariText, $gantiText);
										$dataoutput2 = $this->cekString($dataoutput2, $cariText2, $gantiText2);
										
										$uraioutput2 = $this->cekString($uraioutput, $cariText, $gantiText);
										$uraioutput2 = $this->cekString($uraioutput2, $cariText2, $gantiText2);
										
										$banyakoutput = count($indexoutput_array);
										$indexoutput = "";
										for ($o=0; $o<$banyakoutput; $o++)
										{
											$tempoutput = $indexoutput_array[$o];
											$indexoutput .= $this->dataset->get($this->dataset->fieldName($tempoutput));
											if ($o != ($banyakoutput-1))
											{
												$indexoutput .= ";";
											}
										}
										$data .= "<a href=\"javascript:void(0)\" onclick=\"window.opener.returnpopupdata('".$indexoutput."', '".$uraioutput2."', '".$this->divout."', '".$this->output."'); self.close();\" title=\"".$this->titleLink."\">";
										$data .= $this->dataset->get($i);
										$data .= "</a>";
										break;
									case "filloutput2":
										$dataoutput = $this->dataset->get($this->dataset->fieldName($indexoutput));
										$uraioutput = $this->dataset->get($this->dataset->fieldName($indexurai));
										$cariText = "'";
										$cariText2 = "\"";
										$gantiText = "\'";
										$gantiText2 = "\\\"";
										
										$dataoutput2 = $this->cekString($dataoutput, $cariText, $gantiText);
										$dataoutput2 = $this->cekString($dataoutput2, $cariText2, $gantiText2);
										
										$uraioutput2 = $this->cekString($uraioutput, $cariText, $gantiText);
										$uraioutput2 = $this->cekString($uraioutput2, $cariText2, $gantiText2);
										
										$banyakoutput = count($indexoutput_array);
										$indexoutput = "";
										for ($o=0; $o<$banyakoutput; $o++)
										{
											$tempoutput = $indexoutput_array[$o];
											$indexoutput .= $this->dataset->get($this->dataset->fieldName($tempoutput));
											if ($o != ($banyakoutput-1))
											{
												$indexoutput .= ";";
											}
										}
										$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->jsFillOutput."('".$indexoutput."', '".$uraioutput2."', '".$this->divout."', '".$this->output."');\" title=\"".$this->titleLink."\">";
										$data .= $this->dataset->get($i);
										$data .= "</a>";
										break;
									default:
								}
								$dataoutput = $this->dataset->get($this->dataset->fieldName($indexoutput));
								$uraioutput = $this->dataset->get($this->dataset->fieldName($indexurai));
								$cariText = "'";
								$cariText2 = "\"";
								$gantiText = "\'";
								$gantiText2 = "\\\"";
								
								$dataoutput2 = $this->cekString($dataoutput, $cariText, $gantiText);
								$dataoutput2 = $this->cekString($dataoutput2, $cariText2, $gantiText2);
								
								$uraioutput2 = $this->cekString($uraioutput, $cariText, $gantiText);
								$uraioutput2 = $this->cekString($uraioutput2, $cariText2, $gantiText2);
								
								$banyakoutput = count($indexoutput_array);
								$indexoutput = "";
								for ($o=0; $o<$banyakoutput; $o++)
								{
									$tempoutput = $indexoutput_array[$o];
									$indexoutput .= $this->dataset->get($this->dataset->fieldName($tempoutput));
									if ($o != ($banyakoutput-1))
									{
										$indexoutput .= ";";
									}
								}
							}
							else
							{
								$data_temp = $this->dataset->get($i);
								
								if ($data_temp == "")
								{
									$data .= "&nbsp;";
								}
								else
								{
									$data .= $this->dataset->get($i);
								}
								
							}
						}
						else
						{
							$data_temp = $this->dataset->get($i);
							if ($data_temp == "")
							{
								$data .= "&nbsp;";
							}
							else
							{
								$data .= $this->dataset->get($i);
							}
						}
						$data .= "</td>";
					}
					else
					{
						continue;
					}
					
				}
				if ($this->editData)
				{
					$dataEdit = "";
					$this->dataset->fieldName($i);
					$indexEdit_array = explode(";", $this->indexEdit);
					$banyakIndexEdit = count($indexEdit_array);
					for ($e=0; $e<$banyakIndexEdit; $e++)
					{
						$namaField = $this->dataset->fieldName($indexEdit_array[$e]);
						$dataField = $this->dataset->get($this->dataset->fieldName($indexEdit_array[$e]));
						$cariText = "'";
						$cariText2 = "\"";
						$gantiText = "\'";
						$gantiText2 = "\\\"";
						
						$dataField2 = $this->cekString($dataField, $cariText, $gantiText);
						$dataField2 = $this->cekString($dataField2, $cariText2, $gantiText2);
						
						$dataEdit .= trim($dataField2).";";
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";
					$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->jsEdit."('".$this->tipe."', '".$this->dataAjax."', '".$dataEdit."')\" title=\"Klik untuk edit\" >Edit</a> / ";
					$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->jsHapus."('".$this->tipe."', '".$this->dataAjax."', '".$dataEdit."')\" title=\"Klik untuk hapus\" >Hapus</a>";
					$data .= "</td>";
					$data .= "</tr>";
				}
				else if ($this->tblProses)
				{
					$dataEdit = "";
					$this->dataset->fieldName($i);
					$indexEdit_array = explode(";", $this->indexEdit);
					$banyakIndexEdit = count($indexEdit_array);
					for ($e=0; $e<$banyakIndexEdit; $e++)
					{
						$namaField = $this->dataset->fieldName($indexEdit_array[$e]);
						$dataField = $this->dataset->get($this->dataset->fieldName($indexEdit_array[$e]));
						$cariText = "'";
						$cariText2 = "\"";
						$gantiText = "\'";
						$gantiText2 = "\\\"";
						
						$dataField2 = $this->cekString($dataField, $cariText, $gantiText);
						$dataField2 = $this->cekString($dataField2, $cariText2, $gantiText2);
						
						$dataEdit .= trim($dataField2).";";
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";
					$data .= "<input type=\"button\" value=\"Proses\" id=\"proses".$row."\" ";
					$data .= "onclick=\"".$this->jsProses."('".$row."');\">";
					$data .= "<input type=\"hidden\" name=\"hiddenProses".$row."\" id=\"hiddenProses".$row."\" value=\"".$dataEdit."\">";
					$data .= "</td>";
					$data .= "</tr>";
				}
				
		
				else if ($this->action){
					$dataEdit = "";
					$this->dataset->fieldName($i);
					$indexEdit_array = explode(";", $this->indexEdit);
					$banyakIndexEdit = count($indexEdit_array);
					for ($e=0; $e<$banyakIndexEdit; $e++)
					{
						$namaField = $this->dataset->fieldName($indexEdit_array[$e]);
						$dataField = $this->dataset->get($this->dataset->fieldName($indexEdit_array[$e]));
						$cariText = "'";
						$cariText2 = "\"";
						$gantiText = "\'";
						$gantiText2 = "\\\"";
						
						$dataField2 = $this->cekString($dataField, $cariText, $gantiText);
						$dataField2 = $this->cekString($dataField2, $cariText2, $gantiText2);
						
						$dataEdit .= trim($dataField2).";";
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";					
					$data .= "<a href=\"index.php?act=download&file=".$this->dataset->get(6)."\">".$this->dataset->get(6)."</a>";
					
					$data .= "<input type=\"hidden\" name=\"hiddenProses".$row."\" id=\"hiddenProses".$row."\" value=\"".$dataEdit."\">";
					$data .= "</td>";
					$data .= "</tr>";
				}	
				
				else if ($this->editDatarow)
				{
					$dataEdit = "";
					$this->dataset->fieldName($i);
					$indexEdit_array = explode(";", $this->indexEdit);
					$banyakIndexEdit = count($indexEdit_array);
					for ($e=0; $e<$banyakIndexEdit; $e++)
					{
						$namaField = $this->dataset->fieldName($indexEdit_array[$e]);
						$dataField = $this->dataset->get($indexEdit_array[$e]);
						$cariText = "'";
						$cariText2 = "\"";
						$gantiText = "\'";
						$gantiText2 = "\\\"";
						
						$dataField2 = $this->cekString($dataField, $cariText, $gantiText);
						$dataField2 = $this->cekString($dataField2, $cariText2, $gantiText2);
						
						$dataEdit .= trim($dataField2).";";
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";
					$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->EditJs."('".$dataEdit."')\" title=\"Klik untuk edit\" style=\"color:#AA0000;text-decoration:none;\"><input type=button value=Edit class=\"mbutton\"></a> ";
					$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->Hapusjs."('".$dataEdit."')\" title=\"Klik untuk hapus\" style=\"color:#AA0000;text-decoration:none;\"><input type=button value=Del class=\"mbutton\"></a>";
					$data .= "</td>";
					$data .= "</tr>";
				}//===	
				
				else if ($this->justedit)
				{
					$dataEdit = "";
					$this->dataset->fieldName($i);
					$indexEdit_array = explode(";", $this->indexEdit);
					$banyakIndexEdit = count($indexEdit_array);
					for ($e=0; $e<$banyakIndexEdit; $e++)
					{
						$namaField = $this->dataset->fieldName($indexEdit_array[$e]);
						$dataField = $this->dataset->get($this->dataset->fieldName($indexEdit_array[$e]));
						$cariText = "'";
						$cariText2 = "\"";
						$gantiText = "\'";
						$gantiText2 = "\\\"";
						
						$dataField2 = $this->cekString($dataField, $cariText, $gantiText);
						$dataField2 = $this->cekString($dataField2, $cariText2, $gantiText2);
						
						$dataEdit .= trim($dataField2).";";
					}
					$data .= "<td align='center' class='drill' valign=\"middle\">";
					$data .= "<a href=\"javascript:void(0)\" onclick=\"".$this->justeditbtn."('".$dataEdit."')\" title=\"Klik untuk edit\" >Edit</a>";
					$data .= "</td>";
					$data .= "</tr>";
				}//===	
				
				if ($this->drillDown == true)
				{
					$jumkolom = $this->getColumnCount();
					$data .= "<tr>";
					$data .= "<td colspan='".$jumkolom."' valign=\"middle\">";
					//$data .= "<span class=\"submenu\" id='sub".$nomor."'>";
					
					$data .= "<span id='sub".$nomor.$this->id."'>";
					$data .= "</span>";
					$data .= "</td>";
					$data .= "</tr>";
				}
				$nomor++;
				$row++;
			}			
		}
		else
		{
			$data .= "<tr>";
			$data .= "<td colspan='".$banyakKolom."' align='center'>Tidak ada data</td>";
			$data .= "</tr>";
		}
		return $data;
	}
	
	function drawIcon()
	{
		$balik = "";
		$banyakIcon = count($this->arrayIcon);
		for ($i=0; $i<$banyakIcon; $i++)
		{
			if ($this->arrayIcon[$i][5]=="1")
			{
				if ($this->arrayIcon[$i][0]=="0") {
					$balik .= "<span onclick=\"".$this->arrayIcon[$i][4]."\" style=\"cursor:pointer;\">";
					$balik .= "<img src=\"".$this->arrayIcon[$i][2]."\" >".$this->arrayIcon[$i][3]." ".$data;
					$balik .= "</span>";
				} else {
					$balik .= "<a href=\"javascript:void(0)\" 
									   onclick=\"return ".$this->arrayIcon[$i][4]."\"
									   class=\"fg-button fg-button-icon-left ui-corner-all fg-button-bg\">";
					$balik.="<span class=\"ui-icon  ".$this->arrayIcon[$i][2]."\"></span>";
					$balik .=$this->arrayIcon[$i][3];
					$balik.="</a>";									   
					
				}
			}
		}
		return $balik;
	}
	
	function drawIndex()
	{
		if ($this->banyakData > $this->dataPerPage)
		{
			$banyakPage = ceil($this->banyakData /  $this->dataPerPage);
			if ($this->index != "1")
			{
				$balik .= '<a href="javascript:void(0)" onclick="getData(\''.$this->aksiAjax.'\', \''.$this->divAjax.'\', \'i=1&'.$this->dataAjax.'\', \'\')" title="Halaman Pertama"><img src="images/page-first.gif" align="absmiddle"></a>&nbsp;';
				$balik .= '<a href="javascript:void(0)" onclick="getData(\''.$this->aksiAjax.'\', \''.$this->divAjax.'\', \'i='.($this->index-1).'&'.$this->dataAjax.'\', \'\')" title="Halaman Sebelumnya"><img src="images/page-prev.gif" align="absmiddle"></a>&nbsp;';
			}
			else
			{
				$balik .= '<img src="images/page-first-disabled.gif" align="absmiddle">&nbsp;';
				$balik .= '<img src="images/page-prev-disabled.gif" align="absmiddle">&nbsp;';
			}
			
			$balik .= "<b>Page&nbsp;</b>";
			$balik .= "<input type='text' size='3' id='".$this->kotakIndex."' value='".$this->index."'>&nbsp;";
			$balik .= '<input type="button" value="Go" onclick="getData(\''.$this->aksiAjax.'\', \''.$this->divAjax.'\', \'i=\'+document.getElementById(\''.$this->kotakIndex.'\').value+\'&'.$this->dataAjax.'\', \'\')">&nbsp;';
			$balik .= "<b>Of ".($banyakPage)."</b>&nbsp;";
			
			if ($this->index != ($banyakPage))
			{
				$balik .= '<a href="javascript:void(0)" onclick="getData(\''.$this->aksiAjax.'\', \''.$this->divAjax.'\', \'i='.($this->index+1).'&'.$this->dataAjax.'\', \'\')" title="Halaman Berikutnya"><img src="images/page-next.gif" align="absmiddle"></a>';
				$balik .= "&nbsp;";
				$balik .= '<a href="javascript:void(0)" onclick="getData(\''.$this->aksiAjax.'\', \''.$this->divAjax.'\', \'i='.($banyakPage).'&'.$this->dataAjax.'\', \'\')" title="Halaman Terakhir"><img src="images/page-last.gif" align="absmiddle"></a>';
			}
			else
			{
				$balik .= '<img src="images/page-next-disabled.gif" align="absmiddle">&nbsp;';
				$balik .= '<img src="images/page-last-disabled.gif" align="absmiddle">&nbsp;';
			}
		}
		return $balik;
	}
	
	function execQuery()
	{
		
		$this->connection->connect();
		$banyakPage = ceil($this->banyakData / $this->dataPerPage);
	
		if (($this->index < 1) or ($this->index== "") or ($banyakPage == 0))
		{
			$this->index = 1;
		}
		else if ($this->index > ($banyakPage))
		{
			$this->index = ($banyakPage);
		}
		$awal = (($this->index-1)*($this->dataPerPage));
		$akhir = $awal + ($this->dataPerPage-1);
		
		$query = $this->sql;
		if ($this->dataPerPage != ""){
			$query .= " limit $awal ,$this->dataPerPage";
		}
		else{
			$this->dataPerPage = $this->banyakData;
			$query .= " limit $awal ,$this->dataPerPage";
		}
		
		$this->dataset = $this->connection->query($query);
	}
	
	function execSubsql()
	{
		$this->connection->connect();
		$Query = $this->connection->query($this->sql);
		$this->banyakData = $Query->size();
	}
	
	function showSql()
	{
		return $this->sql;
	}
	
	function getColumnCount()
	{
		return $this->dataset->columnSize();
	}
	
	function acakId($id)
	{
		$nilai = rand(1, 29);
		$nilaiString = str_pad(strval($nilai),2,"0",STR_PAD_LEFT);
		$panjangId = strlen($id);
		$gabungPad = $nilaiString.$panjangId;
		$totalPanjang = strlen($gabungPad);
		$stringMd5 = md5($nilaiString);
		$stringMd5Padd = $stringMd5.$gabungPad.$totalPanjang;
		$acakId = substr_replace($stringMd5Padd, $id, $nilai, strlen($id));
		return $acakId;
	}

}

?>